using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using smartBrowser.Util;

namespace smartBrowser.GUI
{
    public partial class OntologyLinks : Form
    {
        private WebSite website;        

        public OntologyLinks(WebSite site)
        {
            InitializeComponent();
            this.website = site;
            if(this.website.Url != null)
                this.lURL.Text = this.lURL.Text + " " + this.website.Url;
        }

        public void updateOntologyLinks(WebSite site)
        {
            this.website = site;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();          
        }

        private void Links_Load(object sender, EventArgs e)
        {
            this.lboxLinks.Items.Clear();
            this.lbTotalLinks.Text = "";

            if (this.website.OntologyList != null)
            {
                foreach (Ontology.Ontology ontology in this.website.OntologyList)
                {

                    this.lboxLinks.Items.Add(ontology.Name);

                }

                if (this.website.OntologyList.Count > 0)
                    this.lbTotalLinks.Text = "Done! Load " + this.website.OntologyList.Count + " ontologies.";
                else
                    this.lbTotalLinks.Text = "Done! No ontologies found.";
            }



            foreach (Tag tag in this.website.KeyWords.Values)
            {
                this.lvKeywords.Items.Add(tag.Concept);
                this.lvKeywords.Items[this.lvKeywords.Items.Count - 1].SubItems.Add("" + tag.Occurence);
            }


            foreach (Tag tag in this.website.Concepts.Values)
            {
                this.lvConcepts.Items.Add(tag.Concept);
                this.lvConcepts.Items[this.lvConcepts.Items.Count - 1].SubItems.Add("" + tag.Occurence);
            }

        }

        private void Links_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Dispose();
        }

        private void viewOntologyManagerToolStripMenuItem_Click(object sender, EventArgs e)
        {
                String uri = (String)this.lboxLinks.SelectedItem;
                Ontology.Ontology onto = null;
                for (int i = 0; i < this.website.OntologyList.Count; i++)
                {
                    onto = (Ontology.Ontology)this.website.OntologyList[i];
                    if (onto.Name == uri)
                        break;                    
                }
                
                ManagerSmartOntology managerSmartOntology = new ManagerSmartOntology(onto);
                managerSmartOntology.Show();
        }
    }
}